﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VideoRentalShop.Controller
{
    public delegate void ExceptionCatchedCallback(Exception e);


    public class ErrorReceiver
    {
        private List<Exception> _exceptions;
        public ExceptionCatchedCallback ExceptionCatched;
        private static ErrorReceiver _instance;
        public static ErrorReceiver Instance
        {
            get
            {
                if (_instance == null)
                {
                    _instance = new ErrorReceiver();
                }

                return _instance;
            }
        }


        private ErrorReceiver()
        {
            _exceptions = new List<Exception>();
        }


        public void Catched(Exception e)
        {
            System.Diagnostics.Debug.WriteLine("!!! BŁĄD: " + e.Message);
            _exceptions.Add(e);

            if (ExceptionCatched != null)
            {
                ExceptionCatched(e);
            }
        }

        public bool HaveExceptions
        {
            get
            {
                return _exceptions.Count > 0;
            }
        }

        public List<Exception> GetExceptions()
        {
            return _exceptions;
        }
    }
}
